$(function() {
	//确定
	$("#btn_save").on("click", function(){    
		$("#modifypasswordForm").submit();
		return false;
	});
	//取消
	$("#btn_back").on("click", function(){   
		sys.dialog.setData("code", 2);
		sys.closeRemote();
	});
	//验证
	$("#modifypasswordForm").validate({
 		rules: {
 			oldPassword: {
 				required:true
 			},
 			newPassword:{
 				required:true,
 				minlength:5,
        	},
        	confirmPassword:{
        		required:true,
        		equalTo: "#newPassword"
        	}
 		},
 		messages: {
 			oldPassword:{
 				required: '请输入原密码'
        	},
        	newPassword:{
 				required: '请输入新密码'
        	},
        	confirmPassword:{
 				required: '请再次输入新密码',
 				equalTo: "两次密码输入不一致，请重新输入"
        	},
 		},
 		 //错误信息位置设置方法
 		errorPlacement: function(error, element) {
 			error.insertAfter(element);
		},
 		submitHandler: function(form){
 			if (!$(form).valid()){
            	return false;
            } 
 			var oldPassword = $("#oldPassword").val();
 			var newPassword = $("#newPassword").val();
 			$.ajax({
		        type:"post",
		        url:rootPath+"/user/modifyPwd",
		        data:{
		        	oldPassword:oldPassword,
		        	newPassword:newPassword
		        },
		        datatype: "json",
		        success:function(data){
		        	sys.dialog.setData("code", data.resultCode);
		        	sys.dialog.setData("message", data.resultMsg);
		        	sys.closeRemote();
		        }
		        
		     });
			
         }
 	});
	
})